Skip to content

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Aug 13, 2025

Fixes #145328 by making non-lifetime-extended super let reuse the logic used to compute drop scopes for non-lifetime-extended temporaries.

Also fixes #145374, which regressed due to #143376 introducing if let-like scopes for match arms with guards.

Tracking issue for super let: #139076

This is a regression fix / breaking change for macros stably exposing super let, including pin! and format_args!.
Nominating to be discussed alongside #145328: @rustbot label +I-lang-nominated +I-libs-api-nominated

dianne added 2 commits August 13, 2025 01:38
They now use the enclosing temporary scope as their scope, regardless of
which `ScopeData` was used to mark it.
@rustbot
Copy link
Collaborator

rustbot commented Aug 13, 2025

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-lang-nominated Nominated for discussion during a lang team meeting. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Aug 13, 2025
@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang P-lang-drag-0 Lang team prioritization drag level 0.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. and removed P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang labels Aug 13, 2025
@compiler-errors
Copy link
Member

@dianne does this need crater?

@traviscross
Copy link
Contributor

traviscross commented Aug 13, 2025

@bors2 try

@craterbot

This comment was marked as resolved.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 13, 2025
fix drop scope for `super let` bindings within `if let`
@rust-bors
Copy link

rust-bors bot commented Aug 13, 2025

☀️ Try build successful (CI)
Build commit: a498031 (a4980311fb7bb9e7893708e6bd3fbbfb2819fd3d, parent: 350d0ef0ec0493e6d21cfb265cb8211a0e74d766)

@compiler-errors
Copy link
Member

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-145342 created and queued.
🤖 Automatically detected try build a498031
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2025
@rustbot rustbot added the stable-nominated Nominated for backporting to the compiler in the stable channel. label Aug 14, 2025
@compiler-errors compiler-errors added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 14, 2025
@theemathas
Copy link
Contributor

How does #145374 relate to this? The code there doesn't use super let anywhere.

@dianne
Copy link
Contributor Author

dianne commented Aug 14, 2025

Format arguments, e.g. as used by write!, are also implemented in terms of super let. This is visible when printing the HIR of that test case:

f.write_fmt({
        super let args =
            (&pointee.behind_pointer(),
                &ItemIdentifier::path(&ItemIdentifier::nserror()));
        super let args =
            [format_argument::new_display(args.0),
                    format_argument::new_display(args.1)];
        format_arguments::new_v1(&["", ", "], &args)
    })

The interaction between that, old editions not treating block tail expressions as temporary drop scopes, my guard scoping PR, and the existing super let scoping bug is what caused that particular regression.

@traviscross traviscross added T-lang Relevant to the language team I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 14, 2025
@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 16, 2025
@theemathas
Copy link
Contributor

The crater run is clean. No relevant regressions or fixes.

@theemathas
Copy link
Contributor

theemathas commented Aug 16, 2025

Summary of everything so far

Edit: added regression E.

I am naming each of the regressions: A, B, C, D, E, so it's easier to refer to them in the future. For each of them, I give a link to a reproducer of the bug, and I describe when the regression occurred, the prerequisites for code to be affected by the bug, the likelihood (in my opinion) of real user code being affected, and the impact of the bug on such code.

Additionally, there's:

@dianne
Copy link
Contributor Author

dianne commented Aug 16, 2025

With regard to regression D, I imagine it affects edition 2024 as well for match arms where the arm body isn't wrapped in a block expression. It's caused by #143376 extending the surface area of the bug underlying regressions A/B to all match arms with guards where the super let-based macro isn't wrapped in a more deeply nested temporary destruction scope (e.g. a block tail expression in edition 2024). I'm sure you can also get a silent miscompile out of it if you're relying on things like temporary drop order for tuple constructor expressions and constructing a tuple with a write! call in it, but that feels unlikely in real code.

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Aug 19, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Aug 19, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Aug 19, 2025
@Amanieu
Copy link
Member

Amanieu commented Aug 19, 2025

We discussed this in the @rust-lang/libs-api meeting and we're happy to defer to lang for this issue.

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-0 Lang team prioritization drag level 0.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. labels Aug 20, 2025
@apiraino
Copy link
Contributor

apiraino commented Aug 21, 2025

Stable backport declined as per compiler team on Zulip.

We reviewed again the stable backport and our concerns still stand.

@rustbot label -stable-nominated

@jieyouxu

This comment was marked as off-topic.

@craterbot

This comment was marked as off-topic.

@jieyouxu

This comment was marked as off-topic.

@craterbot

This comment was marked as off-topic.

@jieyouxu
Copy link
Member

@craterbot
Copy link
Collaborator

👌 Experiment pr-145342-1 created and queued.
🤖 Automatically detected try build a498031
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2025
@dianne
Copy link
Contributor Author

dianne commented Aug 23, 2025

Something to consider for the FCP: this PR does not make the identity in #145342 (comment) hold. See #145784 (comment) for how it fails to hold in non-extending expressions, due to super let extending the lifetimes of its initializer's temporaries, effectively ignoring block tail expressions' temporary drop scopes. If we want that identity, I think we'd need to rework non-extended super let to have more restrictive temporary lifetime extension rules. Alternatively, whatever identity is used for reasoning about super let may need to account for it having differing meanings in different contexts.

I interpret that issue as separate from the bug this PR fixes: this PR fixes super let's bindings' lifetimes, whereas the identity fails to hold in non-extending expressions due to super let's initializer's temporaries' lifetimes. However, if the FCP is for super let behaving a particular way, then this PR alone doesn't achieve that.

Edit: see #145838 for an implementation of restricting non-extended super let's temporary lifetime extension. I haven't done extensive testing yet, but it might be what's needed.

@craterbot
Copy link
Collaborator

🚧 Experiment pr-145342-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-145342-1 is completed!
📊 0 regressed and 0 fixed (178704 total)
📊 39455 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates={retry_regressed_list_url}

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-nominated Nominated for backporting to the compiler in the beta channel. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression when dropping temporary value in match in older editions pin!() has incorrect/unexpected drop order inside if-let.